{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Count Vowel Substrings of a String"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #hash-table #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #哈希表 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: countVowelSubstrings"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #统计字符串中的元音子字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p><strong>子字符串</strong> 是字符串中的一个连续（非空）的字符序列。</p>\n",
    "\n",
    "<p><strong>元音子字符串</strong> 是 <strong>仅</strong> 由元音（<code>'a'</code>、<code>'e'</code>、<code>'i'</code>、<code>'o'</code> 和 <code>'u'</code>）组成的一个子字符串，且必须包含 <strong>全部五种</strong> 元音。</p>\n",
    "\n",
    "<p>给你一个字符串 <code>word</code> ，统计并返回 <code>word</code> 中 <strong>元音子字符串的数目</strong> 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>word = \"aeiouu\"\n",
    "<strong>输出：</strong>2\n",
    "<strong>解释：</strong>下面列出 word 中的元音子字符串（斜体加粗部分）：\n",
    "- \"<em><strong>aeiou</strong></em>u\"\n",
    "- \"<strong><em>aeiouu</em></strong>\"\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>word = \"unicornarihan\"\n",
    "<strong>输出：</strong>0\n",
    "<strong>解释：</strong>word 中不含 5 种元音，所以也不会存在元音子字符串。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>word = \"cuaieuouac\"\n",
    "<strong>输出：</strong>7\n",
    "<strong>解释：</strong>下面列出 word 中的元音子字符串（斜体加粗部分）：\n",
    "- \"c<em><strong>uaieuo</strong></em>uac\"\n",
    "- \"c<em><strong>uaieuou</strong></em>ac\"\n",
    "- \"c<em><strong>uaieuoua</strong></em>c\"\n",
    "- \"cu<em><strong>aieuo</strong></em>uac\"\n",
    "- \"cu<em><strong>aieuou</strong></em>ac\"\n",
    "- \"cu<em><strong>aieuoua</strong></em>c\"\n",
    "- \"cua<em><strong>ieuoua</strong></em>c\"</pre>\n",
    "\n",
    "<p><strong>示例 4：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>word = \"bbaeixoubb\"\n",
    "<strong>输出：</strong>0\n",
    "<strong>解释：</strong>所有包含全部五种元音的子字符串都含有辅音，所以不存在元音子字符串。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= word.length &lt;= 100</code></li>\n",
    "\t<li><code>word</code> 仅由小写英文字母组成</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [count-vowel-substrings-of-a-string](https://leetcode.cn/problems/count-vowel-substrings-of-a-string/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [count-vowel-substrings-of-a-string](https://leetcode.cn/problems/count-vowel-substrings-of-a-string/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"aeiouu\"', '\"unicornarihan\"', '\"cuaieuouac\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        alp_set = set(\"aeiou\")\n",
    "        cnt = 0\n",
    "        for i in range(n-4):\n",
    "            hast_set = set()\n",
    "            for j in range(i,n):\n",
    "                if word[j] not in alp_set:\n",
    "                    break\n",
    "                else:\n",
    "                    hast_set.add(word[j])\n",
    "                if hast_set == alp_set:\n",
    "                    cnt += 1\n",
    "        return cnt\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        ans = 0\n",
    "        n = len(word)\n",
    "        #  滑动窗口起始坐标\n",
    "        for i in range(n-4):\n",
    "            #  滑动窗口大小\n",
    "            for j in range(i,n+1):\n",
    "                if set(word[i:j]) == set(\"aeiou\") :\n",
    "                    ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        ans = 0\n",
    "        start = 0\n",
    "        vowels = ['a','e','i','o','u']\n",
    "        vowel_count = dict()\n",
    "        for i, c in enumerate(word):\n",
    "            if c in vowels:\n",
    "                if not vowel_count:\n",
    "                    start = i\n",
    "                vowel_count[c] = i\n",
    "                if len(vowel_count) == 5:\n",
    "                    ans += min(vowel_count.values()) - start + 1\n",
    "            elif vowel_count:\n",
    "                vowel_count = dict()\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        alp_set = set(\"aeiou\")\n",
    "        cnt = 0\n",
    "        for i in range(n-4):\n",
    "            hast_set = set()\n",
    "            for j in range(i,n):\n",
    "                if word[j] not in alp_set:\n",
    "                    break\n",
    "                else:\n",
    "                    hast_set.add(word[j])\n",
    "                if hast_set == alp_set:\n",
    "                    cnt += 1\n",
    "        return cnt\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        alp_set = set(\"aeiou\")\n",
    "        cnt = 0\n",
    "        for i in range(n-4):\n",
    "            hast_set = set()\n",
    "            for j in range(i,n):\n",
    "                if word[j] not in alp_set:\n",
    "                    break\n",
    "                else:\n",
    "                    hast_set.add(word[j])\n",
    "                if hast_set == alp_set:\n",
    "                    cnt += 1\n",
    "        return cnt\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int: \n",
    "        ans,n = 0,len(word)\n",
    "        for i in range(n-4):\n",
    "            for j in range(i,n+1):\n",
    "                if set(word[i:j]) == set(\"aeiou\") :\n",
    "                    ans += 1\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        res = 0\n",
    "        vowelset = set(\"aeiou\")   # 所有元音对应的哈希集合\n",
    "        for i in range(n):\n",
    "            # 枚举左端点\n",
    "            charset = set()   # 子串对应的哈希集合\n",
    "            for j in range(i, n):\n",
    "                # 按顺序枚举右端点并更新子串哈希集合及比较\n",
    "                charset.add(word[j])\n",
    "                if charset == vowelset:\n",
    "                    res += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        num = 0\n",
    "        s = set(['a','e','i','o','u'])\n",
    "        for i in range(len(word)):\n",
    "            for j in range(i):\n",
    "                if set(word[j:i + 1]) == s:\n",
    "                    num += 1\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        alp_set = set(\"aeiou\")\n",
    "        cnt = 0\n",
    "        for i in range(n):\n",
    "            hast_set = set()\n",
    "            for j in range(i,n):\n",
    "                if word[j] not in alp_set:\n",
    "                    break\n",
    "                else:\n",
    "                    hast_set.add(word[j])\n",
    "                if hast_set == alp_set:\n",
    "                    cnt += 1\n",
    "        return cnt\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        counter = 0\n",
    "        for i in range(len(word)-1):\n",
    "            for j in range(i+1, len(word)):\n",
    "                new_str = word[i:j+1]\n",
    "\n",
    "                if \"a\" in new_str and \"e\" in new_str and \"i\" in new_str and \"o\" in new_str and \"u\" in new_str and len(set(new_str))==5: \n",
    "                    counter+=1\n",
    "        \n",
    "        return counter\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "VOWEL = 'aeiou'\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        word += 'b'\n",
    "        left = None    # 记录元音子串的开头\n",
    "        ans = 0\n",
    "        for i, c in enumerate(word):\n",
    "            if c in VOWEL:\n",
    "                if left == None:\n",
    "                    left = i\n",
    "            elif left != None:\n",
    "                if len(set(word[left:i])) == 5:\n",
    "                    for a in range(left, i-4):\n",
    "                        for b in range(a+5, i+1):\n",
    "                            if len(set(word[a:b])) == 5:\n",
    "                                ans += 1\n",
    "                left = None\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        res = 0\n",
    "        vowelset = set(\"aeiou\")   # 所有元音对应的哈希集合\n",
    "        for i in range(n):\n",
    "            # 枚举左端点\n",
    "            charset = set()   # 子串对应的哈希集合\n",
    "            for j in range(i, n):\n",
    "                # 按顺序枚举右端点并更新子串哈希集合及比较\n",
    "                charset.add(word[j])\n",
    "                if charset == vowelset:\n",
    "                    res += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        s=0\n",
    "        q=set(\"aeiou\")\n",
    "        for i in range(len(word)):\n",
    "            for j in range(i+4,len(word)):\n",
    "                if set((word[i:j+1]))==q:\n",
    "                    s+=1\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "\n",
    "        def get_cnt(word):\n",
    "\n",
    "            cnt = 0\n",
    "\n",
    "            length = len(word)\n",
    "\n",
    "            for i in range(length-4):\n",
    "\n",
    "                l_set = set()\n",
    "\n",
    "                for j in range(i, length):\n",
    "\n",
    "                    l_set.add(word[j])\n",
    "\n",
    "                    if len(l_set) == 5:\n",
    "\n",
    "                        cnt += length-j\n",
    "\n",
    "                        break\n",
    "\n",
    "            return cnt\n",
    "\n",
    "        return sum(get_cnt(word) for word in re.split(r'[^aeiou]', word))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int: \n",
    "        ans,n = 0,len(word)\n",
    "        for i in range(n-4):\n",
    "            for j in range(i,n+1):\n",
    "                if set(word[i:j]) == set(\"aeiou\") :\n",
    "                    ans += 1\n",
    "        return ans\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        ans = 0\n",
    "        ss = {'a', 'e', 'i', 'o', 'u'}\n",
    "        for i in range(4, len(word)):\n",
    "            for j in range(i):\n",
    "                a = word[j:i+1]\n",
    "                if set(a) == ss:\n",
    "                    ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        yuan_set = set(\"aeiou\")\n",
    "        count = 0\n",
    "        if len(word) < 5:\n",
    "            return count\n",
    "        for i in range(len(word) - 4):\n",
    "            for j in range(i, len(word) + 1):\n",
    "                if set(word[i:j]) == yuan_set:\n",
    "                    count += 1\n",
    "        return count\n",
    "                    \n",
    "\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        alp_set = set(\"aeiou\")\n",
    "        cnt = 0\n",
    "        for i in range(n):\n",
    "            hast_set = set()\n",
    "            for j in range(i,n):\n",
    "                if word[j] not in alp_set:\n",
    "                    break\n",
    "                else:\n",
    "                    hast_set.add(word[j])\n",
    "                if hast_set == alp_set:\n",
    "                    cnt += 1\n",
    "        return cnt\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        l = 0\n",
    "        n = len(word)\n",
    "        res = 0\n",
    "        # l, r 分别记录当前元音字符串的边界\n",
    "        for r in range(n):\n",
    "            if word[r] not in 'aeiou': # 遇到辅音，重置左边界\n",
    "                l = r + 1\n",
    "                continue\n",
    "            if r == n - 1 or word[r + 1] not in 'aeiou': # 已触达当前只包含元音的子字符串的最大右边界，计算该子字符串内有效的元音子字符串数目\n",
    "                # 滑动窗口\n",
    "                # 使用哈希记录当前窗口每个元音的出现次数\n",
    "                char_count = {'a':0,'e':0,'i':0,'o':0,'u':0}\n",
    "                # left, right 分别为当前窗口左右边界\n",
    "                left = l\n",
    "                for right in range(l, r + 1):\n",
    "                    char_count[word[right]] += 1\n",
    "                    while char_count[word[left]] > 1: # 收缩左边界，并保证不同元音的数量不下降\n",
    "                        char_count[word[left]] -= 1\n",
    "                        left += 1\n",
    "                    if all(i >= 1 for i in char_count.values()): # 若当前窗口所有元音都存在，则当前窗口为有效的元音子字符串，且往左扩展的所有子字符串均为有效的元音子字符串\n",
    "                        res += left - l + 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        res = 0\n",
    "        vowelset = set(\"aeiou\")   # 所有元音对应的哈希集合\n",
    "        for i in range(n):\n",
    "            # 枚举左端点\n",
    "            charset = set()   # 子串对应的哈希集合\n",
    "            for j in range(i, n):\n",
    "                # 按顺序枚举右端点并更新子串哈希集合及比较\n",
    "                charset.add(word[j])\n",
    "                if charset == vowelset:\n",
    "                    res += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        res = 0\n",
    "        set1 = set('aeiou')\n",
    "        for i in range(n-1):\n",
    "            for j in range(i+1, n+1):\n",
    "                set2 = set(word[i:j])\n",
    "                if set2 == set1:\n",
    "                    res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        res = 0\n",
    "        vowelset = set(\"aeiou\")   # 所有元音对应的哈希集合\n",
    "        for i in range(n):\n",
    "            # 枚举左端点\n",
    "            charset = set()   # 子串对应的哈希集合\n",
    "            for j in range(i, n):\n",
    "                # 按顺序枚举右端点并更新子串哈希集合及比较\n",
    "                charset.add(word[j])\n",
    "                if charset == vowelset:\n",
    "                    res += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        ans = 0\n",
    "        n = len(word)\n",
    "        #  滑动窗口起始坐标\n",
    "        for i in range(n-4):\n",
    "            #  滑动窗口大小\n",
    "            for j in range(i,n+1):\n",
    "                if set(word[i:j]) == set(\"aeiou\") :\n",
    "                    ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        char = 'aeiou'\n",
    "        ans = 0\n",
    "        ind = 0\n",
    "        n = len(word)\n",
    "        while ind < n:\n",
    "            if word[ind] not in char:\n",
    "                ind += 1\n",
    "            else:\n",
    "                d = {}\n",
    "                l = r = ind\n",
    "                while r < n and word[r] in char:\n",
    "                    d[word[r]] = d.get(word[r], 0) + 1\n",
    "                    r += 1\n",
    "                    if len(d) == 5:\n",
    "                        break\n",
    "                else:\n",
    "                    ind = r\n",
    "                    continue\n",
    "                b = r\n",
    "                while b < n and word[b] in char:\n",
    "                    b += 1\n",
    "                while True:\n",
    "                    ans += b - r + 1\n",
    "                    d[word[l]] -= 1\n",
    "                    if d[word[l]] > 0:\n",
    "                        l += 1\n",
    "                    else:\n",
    "                        while r < b:\n",
    "                            d[word[r]] += 1\n",
    "                            r += 1\n",
    "                            if word[r-1] == word[l]:\n",
    "                                l += 1\n",
    "                                break\n",
    "                        else:\n",
    "                            break\n",
    "                ind = b\n",
    "        return ans\n",
    "                            \n",
    "\n",
    "                \n",
    "\n",
    "\n",
    "                \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        c=0\n",
    "        for i in range(len(word)-4):\n",
    "            for j in range(i,len(word)+1):\n",
    "                if set(word[i:j])==set(\"aeiou\"):\n",
    "                    c+=1\n",
    "        return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        s=0\n",
    "        q=set(\"aeiou\")\n",
    "        for i in range(len(word)):\n",
    "            a=set()\n",
    "            for j in range(i,len(word)):\n",
    "                a.add(word[j])\n",
    "                if a==q:\n",
    "                    s+=1\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        alp_set = set(\"aeiou\")\n",
    "        cnt = 0\n",
    "        for i in range(n-4):\n",
    "            hast_set = set()\n",
    "            for j in range(i,n):\n",
    "                if word[j] not in alp_set:\n",
    "                    break\n",
    "                else:\n",
    "                    hast_set.add(word[j])\n",
    "                if hast_set == alp_set:\n",
    "                    cnt += 1\n",
    "        return cnt\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n=len(word)\n",
    "        count=0\n",
    "        vowe={'a','o','i','e','u'}\n",
    "        if n>=5:\n",
    "            for i in range(n):\n",
    "                subWord=set()\n",
    "                for j in range(i,n):\n",
    "                    subWord.add(word[j])\n",
    "                    if subWord==vowe:\n",
    "                        count+=1\n",
    "        else:\n",
    "            return 0\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        alp_set = set(\"aeiou\")\n",
    "        cnt = 0\n",
    "        for i in range(n-4):\n",
    "            hast_set = set()\n",
    "            for j in range(i,n):\n",
    "                if word[j] not in alp_set:\n",
    "                    break\n",
    "                else:\n",
    "                    hast_set.add(word[j])\n",
    "                if hast_set == alp_set:\n",
    "                    cnt += 1\n",
    "        return cnt\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        def check(s):\n",
    "            return all(c in s for c in 'aeiou') and  len(Counter(s)) == 5\n",
    "        return sum(check(word[i:j+1]) for i in range(len(word)) for j in range(i, len(word)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        ans = 0\n",
    "        n = len(word)\n",
    "        #  滑动窗口起始坐标\n",
    "        for i in range(n-4):\n",
    "            #  滑动窗口大小\n",
    "            for j in range(i,n+1):\n",
    "                if set(word[i:j]) == set(\"aeiou\") :\n",
    "                    ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        vowel = 'aeiou'\n",
    "        n = len(word)\n",
    "        count = 0\n",
    "        for start in range(n):\n",
    "            for end in range(start, n):\n",
    "                if word[end] not in vowel:\n",
    "                    break\n",
    "                elif len(set(word[start: end+1])) == 5:\n",
    "                    count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        ans = 0\n",
    "        start = 0\n",
    "        vowels = ['a','e','i','o','u']\n",
    "        vowel_count = dict()\n",
    "        for i, c in enumerate(word):\n",
    "            if c in vowels:\n",
    "                if not vowel_count:\n",
    "                    start = i\n",
    "                vowel_count[c] = i\n",
    "                if len(vowel_count) == 5:\n",
    "                    ans += min(vowel_count.values()) - start + 1\n",
    "            elif vowel_count:\n",
    "                vowel_count = dict()\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        s=0\n",
    "        q={\"a\",\"e\",\"i\",\"o\",\"u\"}\n",
    "        for i in range(len(word)):\n",
    "            for j in range(i+4,len(word)):\n",
    "                if set((word[i:j+1]))==q:\n",
    "                    s+=1\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        c = 0\n",
    "        vowel = set('aeiou')\n",
    "        n = len(word)\n",
    "        for i in range(n):\n",
    "            for j in range(i+4, n):\n",
    "                sub = set(word[i:j + 1])\n",
    "                if sub == vowel:\n",
    "                    c += 1\n",
    "                if sub - vowel:\n",
    "                    break\n",
    "        return c\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        def check(w):\n",
    "            d = ['a','e','i','o','u']\n",
    "            for dd in d:\n",
    "                if dd not in w:\n",
    "                    return False\n",
    "            return True\n",
    "        #双指针\n",
    "        d = {'a','e','i','o','u'}\n",
    "        ans = l = r = 0\n",
    "        # word += 'p'\n",
    "        n = len(word)\n",
    "        while r < n:\n",
    "            if word[r] not in d:#首字母不是原音\n",
    "                r+=1\n",
    "                l = r \n",
    "            else:\n",
    "                r+=1\n",
    "                if check(word[l:r]):\n",
    "                    ans += 1\n",
    "                    t = l\n",
    "                    l+=1\n",
    "                    while check(word[l:r]):\n",
    "                        ans += 1\n",
    "                        l+=1\n",
    "                    l = t\n",
    "        return ans\n",
    "        \n",
    "                \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        res = 0\n",
    "        vowelset = set(\"aeiou\")   # 所有元音对应的哈希集合\n",
    "        for i in range(n):\n",
    "            # 枚举左端点\n",
    "            charset = set()   # 子串对应的哈希集合\n",
    "            for j in range(i, n):\n",
    "                # 按顺序枚举右端点并更新子串哈希集合及比较\n",
    "                charset.add(word[j])\n",
    "                if charset == vowelset:\n",
    "                    res += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        res = 0\n",
    "        vowelset = set(\"aeiou\")   # 所有元音对应的哈希集合\n",
    "        for i in range(n):\n",
    "            # 枚举左端点\n",
    "            charset = set()   # 子串对应的哈希集合\n",
    "            for j in range(i, n):\n",
    "                # 按顺序枚举右端点并更新子串哈希集合及比较\n",
    "                charset.add(word[j])\n",
    "                if charset == vowelset:\n",
    "                    res += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        ans,n=0,len(word)\n",
    "        for i in range(n-4):\n",
    "            for j in range(i,n+1):\n",
    "                if set(word[i:j])==set(\"aeiou\"):\n",
    "                    ans+=1\n",
    "        return ans            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        ans,n = 0,len(word)\n",
    "        #  滑动窗口起始坐标\n",
    "        for i in range(n-4):\n",
    "            #  滑动窗口大小\n",
    "            for j in range(i,n+1):\n",
    "                if set(word[i:j]) == set(\"aeiou\") :\n",
    "                    ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        yuan_yin=[\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "        word=list(word)\n",
    "        i=0\n",
    "        res=0\n",
    "        while i<len(word)-4:\n",
    "            if word[i] in yuan_yin:\n",
    "                for j in range(i+1, len(word)):\n",
    "                    if word[j] not in yuan_yin:\n",
    "                        break\n",
    "                    else:\n",
    "                        if set(word[i:j+1])==set(yuan_yin):\n",
    "                            res+=1\n",
    "                \n",
    "            i+=1\n",
    "        return res\n",
    "                \n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int: \n",
    "        ans,n = 0,len(word)\n",
    "        for i in range(n-4):\n",
    "            for j in range(i,n+1):\n",
    "                if set(word[i:j]) == set(\"aeiou\") :\n",
    "                    ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        vowel_set = set('aoeiu')\n",
    "        cnt = 0\n",
    "        for i in range(0,len(word)-4):\n",
    "            m = len(word)-i-5\n",
    "            for j in range(0, m+1):\n",
    "                set2 = set(word[i: i+j+5])\n",
    "                if set2 == vowel_set:\n",
    "                    cnt +=1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        t=['a','e','i','o','u']\n",
    "        n=len(word)\n",
    "        ans=0\n",
    "        for i in range(n-4):\n",
    "            for j in range(i,n+1):\n",
    "                if set(word[i:j])==set(\"aeiou\"):\n",
    "                    ans+=1\n",
    "        return ans\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        alp_set = set(\"aeiou\")\n",
    "        cnt = 0\n",
    "        for i in range(n-4):\n",
    "            hast_set = set()\n",
    "            for j in range(i,n):\n",
    "                if word[j] not in alp_set:\n",
    "                    break\n",
    "                else:\n",
    "                    hast_set.add(word[j])\n",
    "                if hast_set == alp_set:\n",
    "                    cnt += 1\n",
    "        return cnt\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        cnt = 0\n",
    "        length = len(word)\n",
    "        for i in range(length - 4):\n",
    "            for j in range(i, length + 1):\n",
    "                if set(word[i:j]) == set('aeiou'):\n",
    "                    cnt += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        vowels = set('aeiou')\n",
    "        cnt = 0\n",
    "        # 枚举左端点\n",
    "        for left in range(len(word) - 5 + 1):\n",
    "            windowSet = set(word[left: left + 4])\n",
    "            # 枚举右端点\n",
    "            for right in range(left + 5 - 1, len(word)):\n",
    "                windowSet.add(word[right])\n",
    "                if windowSet == vowels:\n",
    "                    cnt += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        res = 0\n",
    "        vowelset = set(\"aeiou\")   # 所有元音对应的哈希集合\n",
    "        for i in range(n):\n",
    "            # 枚举左端点\n",
    "            charset = set()   # 子串对应的哈希集合\n",
    "            for j in range(i, n):\n",
    "                # 按顺序枚举右端点并更新子串哈希集合及比较\n",
    "                charset.add(word[j])\n",
    "                if charset == vowelset:\n",
    "                    res += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        alp_set = set(\"aeiou\")\n",
    "        cnt = 0\n",
    "        for i in range(n):\n",
    "            hast_set = set()\n",
    "            for j in range(i,n):\n",
    "                if word[j] not in alp_set:\n",
    "                    break\n",
    "                else:\n",
    "                    hast_set.add(word[j])\n",
    "                if hast_set == alp_set:\n",
    "                    cnt += 1\n",
    "        return cnt\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        def get_cnt(word):\n",
    "            cnt = 0\n",
    "            length = len(word)\n",
    "            for i in range(length-4):\n",
    "                l_set = set()\n",
    "                for j in range(i, length):\n",
    "                    l_set.add(word[j])\n",
    "                    if len(l_set) == 5:\n",
    "                        cnt += length-j\n",
    "                        break\n",
    "            return cnt\n",
    "        return sum(get_cnt(word) for word in re.split(r'[^aeiou]', word))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        alp_set = set(\"aeiou\")\n",
    "        cnt = 0\n",
    "        for i in range(n-4):\n",
    "            hast_set = set()\n",
    "            for j in range(i,n):\n",
    "                if word[j] not in alp_set:\n",
    "                    break\n",
    "                else:\n",
    "                    hast_set.add(word[j])\n",
    "                if hast_set == alp_set:\n",
    "                    cnt += 1\n",
    "        return cnt\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:        \n",
    "        yi=['a','e','i','o','u']\n",
    "        yi.sort()\n",
    "        count=0\n",
    "        for i in range(len(word)):\n",
    "            for j in range(i+5,len(word)+1):\n",
    "                t=list(set(word[i:j]))\n",
    "                t.sort()\n",
    "                if len(t)==5 and t==yi:\n",
    "                    count+=1                \n",
    "        return count\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        res = 0\n",
    "        vowelset = set(\"aeiou\")   # 所有元音对应的哈希集合\n",
    "        for i in range(n):\n",
    "            # 枚举左端点\n",
    "            charset = set()   # 子串对应的哈希集合\n",
    "            for j in range(i, n):\n",
    "                # 按顺序枚举右端点并更新子串哈希集合及比较\n",
    "                charset.add(word[j])\n",
    "                if charset == vowelset:\n",
    "                    res += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        res = 0\n",
    "        vowelset = set(\"aeiou\")   # 所有元音对应的哈希集合\n",
    "        for i in range(n):\n",
    "            # 枚举左端点\n",
    "            charset = set()   # 子串对应的哈希集合\n",
    "            for j in range(i, n):\n",
    "                # 按顺序枚举右端点并更新子串哈希集合及比较\n",
    "                charset.add(word[j])\n",
    "                if charset == vowelset:\n",
    "                    res += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        yuan_set = set(\"aeiou\")\n",
    "        count = 0\n",
    "        len_word = len(word)\n",
    "        if len_word < 5:\n",
    "            return count\n",
    "        for i in range(len_word - 4):\n",
    "            for j in range(i, len_word + 1):\n",
    "                if set(word[i:j]) == yuan_set:\n",
    "                    count += 1\n",
    "        return count\n",
    "                    \n",
    "\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        c = 0\n",
    "        vowel = set('aeiou')\n",
    "        n = len(word)\n",
    "        for i in range(n):\n",
    "            for j in range(i+4, n):\n",
    "                sub = set(word[i:j + 1])\n",
    "                if sub == vowel:\n",
    "                    c += 1\n",
    "        return c\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        res = 0\n",
    "        vowelset = set(\"aeiou\")   # 所有元音对应的哈希集合\n",
    "        for i in range(n):\n",
    "            # 枚举左端点\n",
    "            charset = set()   # 子串对应的哈希集合\n",
    "            for j in range(i, n):\n",
    "                # 按顺序枚举右端点并更新子串哈希集合及比较\n",
    "                charset.add(word[j])\n",
    "                if charset == vowelset:\n",
    "                    res += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        ans = 0\n",
    "        n = len(word)\n",
    "        #  滑动窗口起始坐标\n",
    "        for i in range(n):\n",
    "            #  滑动窗口大小\n",
    "            for j in range(i,n+1):\n",
    "                if set(word[i:j]) == set(\"aeiou\") :\n",
    "                    ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        i, ans = 0, 0\n",
    "        lst = []\n",
    "        for j in range(len(word)):\n",
    "            if word[j] in \"aeiou\":\n",
    "                if word[i] not in \"aeiou\":\n",
    "                    i = j\n",
    "            else:\n",
    "                if word[i] in \"aeiou\":\n",
    "                    lst.append(word[i: j])\n",
    "                i = j\n",
    "        if word[i] in \"aeiou\":\n",
    "            lst.append(word[i:])\n",
    "\n",
    "        for s in lst:\n",
    "            if len(s) >= 5:\n",
    "                for m in range(len(s)):\n",
    "                    for n in range(m + 5, len(s) + 1):\n",
    "                        if len(set(s[m: n])) == 5:\n",
    "                            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n=len(word)\n",
    "        w=set(\"aeiou\")\n",
    "        ans=0\n",
    "        for i in range(n-4):\n",
    "            for j in range(i+4,n):\n",
    "                if set(word[i:j+1])==w:\n",
    "                    ans+=1\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        c = 0\n",
    "        vowel = set('aeiou')\n",
    "        n = len(word)\n",
    "        for i in range(n):\n",
    "            for j in range(i+4, n):\n",
    "                sub = set(word[i:j + 1])\n",
    "                if len(sub) >= 5 and not(sub - vowel):\n",
    "                    c += 1\n",
    "        return c\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        r = 0\n",
    "        for i in range(len(word)):\n",
    "            if word[i] in  \"aeiou\":\n",
    "                t = word[i]\n",
    "                for j in range(i+1, len(word)):\n",
    "                    if word[j] in \"aeiou\":\n",
    "                        t += word[j]\n",
    "                    else:\n",
    "                        break\n",
    "                    if len(t) >= 5:\n",
    "                        if \"a\" in t and \"e\" in t and \"i\" in t and \"o\" in t and \"u\" in t:\n",
    "                            r += 1\n",
    "        return r\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        ans = 0\n",
    "        ss = {'a', 'e', 'i', 'o', 'u'}\n",
    "        for i in range(len(word)):\n",
    "            for j in range(i):\n",
    "                a = word[j:i+1]\n",
    "                if set(a) == ss:\n",
    "                    ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        ans = 0\n",
    "        s = set(['a','e','i','o','u']) #set会自动排序\n",
    "        for i in range(len(word)-4):\n",
    "            for j in range(i+5,len(word)+1):\n",
    "                if set(word[i:j]) == s:\n",
    "                    ans += 1\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        vowels={'a','e','i','o','u'}\n",
    "        n=len(word)\n",
    "        count=0\n",
    "        for i in range(n-4):\n",
    "            for j in range(i+4,n+1):\n",
    "                if set(word[i:j])==vowels:\n",
    "                    count+=1\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:        \n",
    "        yi=['a','e','i','o','u']\n",
    "        yi.sort()\n",
    "        count=0\n",
    "        for i in range(len(word)):\n",
    "            for j in range(i+4,len(word)+1):\n",
    "                t=list(set(word[i:j]))\n",
    "                t.sort()\n",
    "                if len(t)==5 and t==yi:\n",
    "                    count+=1                \n",
    "        return count\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        ans = 0\n",
    "        origin_stand = {'a', 'e', 'i', 'o', 'u'}\n",
    "        for i, w in enumerate(word):\n",
    "            stand = {'a', 'e', 'i', 'o', 'u'}\n",
    "            if w in stand:\n",
    "                stand.remove(w)\n",
    "            else:\n",
    "                continue\n",
    "            for w2 in word[i + 1:]:\n",
    "                if w2 not in origin_stand:\n",
    "                    break\n",
    "                if w2 in stand:\n",
    "                    stand.remove(w2)\n",
    "                if not stand:\n",
    "                    ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        alp_set = set(\"aeiou\")\n",
    "        cnt = 0\n",
    "        for i in range(n-4):\n",
    "            hast_set = set()\n",
    "            for j in range(i,n):\n",
    "                if word[j] not in alp_set:\n",
    "                    break\n",
    "                else:\n",
    "                    hast_set.add(word[j])\n",
    "                if hast_set == alp_set:\n",
    "                    cnt += 1\n",
    "        return cnt\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        vowel_set = set('aoeiu')\n",
    "        cnt = 0\n",
    "        for i in range(0,len(word)-4):\n",
    "            m = len(word)-i-5\n",
    "            for j in range(0, m+1):\n",
    "                set2 = set(word[i: i+j+5])\n",
    "                if set2 == vowel_set:\n",
    "                    cnt +=1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        def get_cnt(word):\n",
    "            cnt = 0\n",
    "            length = len(word)\n",
    "            for i in range(length-4):\n",
    "                l_set = set()\n",
    "                for j in range(i, length):\n",
    "                    l_set.add(word[j])\n",
    "                    if len(l_set) == 5:\n",
    "                        cnt += length-j\n",
    "                        break\n",
    "            return cnt\n",
    "        return sum(get_cnt(word) for word in re.split(r'[^aeiou]', word))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int: \n",
    "        ans,n = 0,len(word)\n",
    "        for i in range(n-4):\n",
    "            for j in range(i,n+1):\n",
    "                if set(word[i:j]) == set(\"aeiou\") :\n",
    "                    ans += 1\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        ans,n = 0,len(word)\n",
    "        for i in range(n-4):\n",
    "            for j in range(i,n+1):\n",
    "                if set(word[i:j]) == set(\"aeiou\") :\n",
    "                    ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        result = 0\n",
    "        start_index = []\n",
    "        targets = set(['a', 'e', 'i', 'o', 'u'])\n",
    "        for i, c in enumerate(word):\n",
    "            if c in targets:\n",
    "                start_index.append(i)\n",
    "            pass\n",
    "        for i in start_index:\n",
    "            end = i + 4\n",
    "            for c in word[i:end + 1]:\n",
    "                if c not in targets:\n",
    "                    break\n",
    "                pass\n",
    "            else:\n",
    "                while end < len(word):\n",
    "                    if word[end] not in targets:\n",
    "                        break\n",
    "                        pass\n",
    "                    else:\n",
    "                        if set(word[i:end + 1]) == targets:\n",
    "                            result += 1\n",
    "                            end += 1\n",
    "                            pass\n",
    "                        else:\n",
    "                            end += 1\n",
    "            pass\n",
    "        return result\n",
    "        pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        w=['a','e','i','o','u']\n",
    "        c=0\n",
    "        for i in range(len(word)-4):\n",
    "            if word[i] not in w:\n",
    "                continue\n",
    "            else:\n",
    "                w1=w[::]\n",
    "                w1.remove(word[i])\n",
    "                for j in range(i+1,len(word)):\n",
    "                    if word[j] in w and word[j] in w1:\n",
    "                        w1.remove(word[j])\n",
    "                    elif word[j] in w and word[j] not in w1:\n",
    "                        pass\n",
    "                    else:\n",
    "                        break\n",
    "                    if len(w1)==0:\n",
    "                        c+=1\n",
    "        return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        i, ans = 0, 0\n",
    "        for j in range(len(word)):\n",
    "            if word[j] in \"aeiou\":\n",
    "                if word[i] not in \"aeiou\":\n",
    "                    i = j\n",
    "            else:\n",
    "                if word[i] in \"aeiou\":\n",
    "                    s = word[i: j]\n",
    "                    if len(s) >= 5:\n",
    "                        for m in range(len(s)):\n",
    "                            for n in range(m + 5, len(s) + 1):\n",
    "                                if len(set(s[m: n])) == 5:\n",
    "                                    print(s[m: n])\n",
    "                                    ans += 1\n",
    "                i = j\n",
    "        if word[i] in \"aeiou\":\n",
    "            s = word[i:]\n",
    "            if len(s) >= 5:\n",
    "                for m in range(len(s)):\n",
    "                    for n in range(m + 5, len(s) + 1):\n",
    "                        if len(set(s[m: n])) == 5:\n",
    "                            print(s[m: n])\n",
    "                            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        def check(s: str) -> bool:\n",
    "            return set(s) == {'a','e','i','o','u'}\n",
    "            # for _ in 'aeiou':\n",
    "            #     if _ not in s:\n",
    "            #         return False\n",
    "            # return True\n",
    "        n = len(word)\n",
    "        ans = 0\n",
    "        for i in range(n):\n",
    "            # if word[i] not in 'aeiou':\n",
    "                # continue\n",
    "            for j in range(i, n):\n",
    "                if check(word[i:j + 1]):\n",
    "                    ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        n = len(word)\n",
    "        res = 0\n",
    "        vowelset = set(\"aeiou\")   # 所有元音对应的哈希集合\n",
    "        for i in range(n):\n",
    "            # 枚举左端点\n",
    "            charset = set()   # 子串对应的哈希集合\n",
    "            for j in range(i, n):\n",
    "                # 按顺序枚举右端点并更新子串哈希集合及比较\n",
    "                charset.add(word[j])\n",
    "                if charset == vowelset:\n",
    "                    res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        def check(txt: str) -> int:\n",
    "            # return 0 uaie\n",
    "            # return 1 uaieo\n",
    "            # return 2 uaieox // uaix\n",
    "            d = Counter(txt)\n",
    "            c = ['a','e','i','o','u']\n",
    "\n",
    "            if all(k in c for k in d):\n",
    "                return int(all(g in d for g in c))       \n",
    "            else:\n",
    "                return 2\n",
    "\n",
    "        n = len(word)\n",
    "        if n < 5:\n",
    "            return 0\n",
    "        cnt = 0\n",
    "        s = set([])\n",
    "        start, end = 0, 5\n",
    "        while start < n - 4:\n",
    "            while end <= n:\n",
    "                c = check(word[start:end])\n",
    "                if c <= 1:\n",
    "                    cnt += c \n",
    "                else:\n",
    "                    break\n",
    "                end += 1\n",
    "            start += 1\n",
    "            end = start + 5\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        s=0\n",
    "        q={\"a\",\"e\",\"i\",\"o\",\"u\"}\n",
    "        for i in range(len(word)):\n",
    "            for j in range(i+4,len(word)):\n",
    "                if set(list(word[i:j+1]))==q:\n",
    "                    s+=1\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countVowelSubstrings(self, word: str) -> int:\n",
    "        # split\n",
    "        vowels = []\n",
    "        tmp = []\n",
    "        word = list(word)\n",
    "        for c in word:\n",
    "            if c not in ['a', 'e', 'i', 'o', 'u']:\n",
    "                if len(tmp):\n",
    "                    vowels.append(tmp)\n",
    "                    tmp = []\n",
    "            else:\n",
    "                tmp.append(c)\n",
    "        if len(tmp):\n",
    "            vowels.append(tmp)\n",
    "        \n",
    "        def count(s):\n",
    "            tmp = 0\n",
    "            cnt = {'a':0, 'e':0, 'i':0, 'o':0, 'u':0}\n",
    "            n,i,j = len(s),0,0\n",
    "            while j < n:\n",
    "                while j < n and 0 in cnt.values():\n",
    "                    cnt[s[j]] += 1\n",
    "                    j += 1\n",
    "                if 0 in cnt.values():\n",
    "                    return tmp\n",
    "                while i < j and 0 not in cnt.values():\n",
    "                    tmp += (n-j+1)\n",
    "                    cnt[s[i]] -= 1\n",
    "                    i += 1\n",
    "            return tmp\n",
    "        \n",
    "        ans = 0\n",
    "        for vowel in vowels:\n",
    "           ans += count(vowel)\n",
    "        return ans\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
